|
|
|
|
|
|
|
When accessing data from a database, you would have to define the relationship of the tables for every SQL statement that you would create. The relationships are actually defined in the WHERE clause of the SQL statement. The following SQL statement accesses the tables from the BIBLIO database that comes with Visual Basic: |
|
|
|
|
|
|
|
|
SELECT Titles.ISBN, Titles.Title, Authors.[Year Born]
FROM Authors Where (Titles.ISBN = [Title Author].ISBN) and Authors.Au_ID
= [Title Author].Au_ID; |
|
|
|
|
|
|
|
|
As you can see, the relationship is actually defined by using the keys in the different tables that have matching information. When the database executes this SQL statement, it looks for records in the first table where the data in the key field matches the data in the second tables' key field. It returns only records where there's a match between these keys. |
|
|
|
|
|
|
|
|
The problem with using databases in an application is that every time you need to access more than one table, you need to redefine the relationships and fields that you want in a SQL statement. If you're designing an application with very little database interaction, you could probably get away with doing this; a more complex application would very quickly become difficult to maintain. If you need to change what data is being retrieved, the SQL statement must be modified. Queries are a feature that you can use in most databases. |
|
|
|
|
|
|
|
|
A query is nothing more than a SQL statement defined directly in the database. When using these defined queries, the database processes the data request faster. If you needed to access data from three tables in the BIBLIO database, you could code the following SQL statement: |
|
|
|
|
|
|
|
|
SELECT Titles.Title, [Title Author].ISBN, Authors.Author FROM Authors
INNER JOIN (Titles INNER JOIN [Title Author] ON Titles.ISBN
= [Title Author].ISBN) ON Authors.Au_ID = [Title Author].Au_ID; |
|
|
|
|
|
|
|
|
Or you could define this query in the database so that your SQL statement could be simplified: |
|
|
|
|
|
|
|
|
Select * from ThreeTableQuery |
|
|
|
|
|
|
|
|
Most database tools allow you to define queries in the database, allowing you to concentrate on the design of your application. |
|
|
|
|
|
|
|
|
After you understand what goes into a database design, you need to understand the language used to access the data in the database. SQL is the language that every computer |
|
|
|
|
|